package com.yitao.cms.controller.product;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.dto.product.ProductShareCopywritingDto;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.service.product.ProductShareCopywritingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @Date: 2019/12/11 11:21
 * @Author: Kien
 */
@Api(value = "/cms/productShare", description = "商品运营后台相关接口", tags = {"cms-product-share"})
@RestController
@RequestMapping(value = "/productShare", produces = {"application/json"})
public class ProductShareCopywritingController {
    @Autowired
    private ProductShareCopywritingService productShareCopywritingService;

    @ApiOperation("新增分享文案")
    @LogAnnotation(targetType = "ProductShareSave", remark = "新增商品分享文案")
    @RequestMapping(value = "/saveProductShare", method = RequestMethod.POST)
    public DataOutput<ProductShareCopywritingDto> saveProductShare(@ApiParam(value = "文案") @RequestParam(value = "shareDescribe") String shareDescribe,
                                                       HttpServletRequest request) {
        return productShareCopywritingService.saveProductShare(shareDescribe, request);
    }

    @ApiOperation("编辑分享文案")
    @LogAnnotation(targetType = "ProductShareUpdate", remark = "编辑商品分享文案")
    @RequestMapping(value = "/updateProductShare", method = RequestMethod.POST)
    public DataOutput updateProductShare(@ApiParam(value = "id") @RequestParam(value = "id") Long id,
                                                                     @ApiParam(value = "文案") @RequestParam(value = "shareDescribe") String shareDescribe,
                                                                     HttpServletRequest request) {
        return productShareCopywritingService.updateProductShare(id, shareDescribe, request);
    }

    @ApiOperation("删除分享文案")
    @LogAnnotation(targetType = "ProductShareDelete", remark = "删除商品分享文案")
    @RequestMapping(value = "/delProductShare", method = RequestMethod.POST)
    public DataOutput delProductShare(@ApiParam(value = "id") @RequestParam(value = "id") Long id,
                                                                  HttpServletRequest request) {
        return productShareCopywritingService.delProductShare(id, request);
    }

    @ApiOperation("商品列表")
    @RequestMapping(value = "/findProductShareList", method = RequestMethod.POST)
    public PagedOutput<ProductShareCopywritingDto> findProductInfoList(@ApiParam(value = "文案内容") @RequestParam(value = "shareDescribe", required = false) String shareDescribe,
                                                                       @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                                       @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize,
                                                                        HttpServletRequest request) {
        return productShareCopywritingService.findProductShareList(shareDescribe, pageNo, pageSize, request);
    }

}
